import request from "../request"

// 用户登录
export const login = (data) => {
    return request({
        url: "/auth/login",
        method: "POST",
        data,
    })
}

// 验证码登录
export const loginWithCode = (data) => {
    return request({
        url: "/auth/login-with-code",
        method: "POST",
        data,
    })
}

// 用户注册
export const register = (data) => {
    return request({
        url: "/auth/register",
        method: "POST",
        data,
    })
}

// 发送邮箱验证码（注册用）
export const sendVerificationCode = (data) => {
    return request({
        url: "/auth/send-verification-code",
        method: "POST",
        data,
    })
}

// 发送登录验证码（为已存在的用户发送登录验证码）
export const sendLoginVerificationCode = (data) => {
    return request({
        url: "/auth/send-login-verification-code",
        method: "POST",
        data,
    })
}

// 用户登出
export const logout = () => {
    return request({
        url: "/auth/logout",
        method: "POST",
    })
}

// 检查用户名是否可用
export const checkUsername = (username) => {
    return request({
        url: "/auth/check-username",
        method: "GET",
        params: { username },
    })
}

// 检查邮箱是否可用
export const checkEmail = (email) => {
    return request({
        url: "/auth/check-email",
        method: "GET",
        params: { email },
    })
}

// 获取用户个人信息
export const getUserProfile = () => {
    return request({
        url: "/auth/profile",
        method: "GET",
    })
}

// 刷新令牌（可直接调用，也由拦截器自动调用）
export const refreshToken = (refreshToken) => {
    return request({
        url: "/auth/refresh",
        method: "POST",
        data: { refreshToken },
    })
}

// 更新用户名
export const updateUsername = (data) => {
    return request({
        url: "/auth/update-username",
        method: "PUT",
        data,
    })
}

// 更新密码
export const updatePassword = (data) => {
    return request({
        url: "/auth/update-password",
        method: "PUT",
        data,
    })
}
